//
//  TTBankCardViewCell.m
//  TaoTuo
//
//  Created by admin on 2019/10/9.
//  Copyright © 2019 admin. All rights reserved.
//

#import "TTBankCardViewCell.h"

@interface TTBankCardViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *bgImageView;
@property (weak, nonatomic) IBOutlet UIImageView *bankImageView;
@property (weak, nonatomic) IBOutlet UILabel *bankNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *receiveManLabel;
@property (weak, nonatomic) IBOutlet UILabel *openBankLabel;    // 开户行
@property (weak, nonatomic) IBOutlet UILabel *bankNumLabel;
@property (weak, nonatomic) IBOutlet UIButton *fuzhiBtn;

@end

@implementation TTBankCardViewCell

static NSDictionary * getBankCardInfo() {
    return @{
        @"工行" : @[[UIImage imageNamed:@"gonghang"], [UIImage imageNamed:@"gonghangbg"]],
        @"农行" : @[[UIImage imageNamed:@"nonghang"], [UIImage imageNamed:@"nonghangbg"]],
        @"建行" : @[[UIImage imageNamed:@"jianhang"], [UIImage imageNamed:@"jianhangbg"]],
        @"中国银行" : @[[UIImage imageNamed:@"guohang"], [UIImage imageNamed:@"guohangbg"]]
    };
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.bankImageView.layer.cornerRadius = 20;
//    self.bankImageView.layer.masksToBounds = YES;
    
    self.bgImageView.layer.cornerRadius = 5;
    
    self.fuzhiBtn.layer.cornerRadius = 13;
    self.fuzhiBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    self.fuzhiBtn.layer.borderWidth = 1;
    self.fuzhiBtn.contentEdgeInsets = UIEdgeInsetsMake(6, 8, 6, 8);
    
    
}

- (void)setModel:(TTBankCardModel *)model
{
    _model = model;
    
    NSString *key;
    if ([model.BankName containsString:@"工商"]) {
        key = @"工行";
    } else if ([model.BankName containsString:@"农业"]) {
        key = @"农行";
    } else if ([model.BankName containsString:@"建设"]) {
        key = @"建行";
    } else if ([model.BankName containsString:@"中国银行"]) {
        key = @"中国银行";
    }
    
    NSArray *array = getBankCardInfo()[key];
    self.bankImageView.image = array.firstObject;
    self.bgImageView.image = array.lastObject;
    
    self.bankNameLabel.text = model.BankName;
    self.receiveManLabel.text = [NSString stringWithFormat:@"收款人:%@", model.BankAccountName];
    self.openBankLabel.text = [NSString stringWithFormat:@"开户行:%@", model.OpenBank];
    self.bankNumLabel.text = [model.CardNo segmentBankCardNumWithEachSegmentCount:4 separator:@" "];
    
}


// 复制卡号
- (IBAction)clickCopyBtn:(id)sender {
    
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = self.model.CardNo;
    [[UIApplication sharedApplication].keyWindow makeToast:@"已复制到剪贴板" duration:1 position:CSToastPositionCenter];
    
}


- (void)setFrame:(CGRect)frame
{
    frame.origin.x += 10;
    frame.size.width -= 20;

    frame.origin.y += 5;
    frame.size.height -= 10;

    [super setFrame:frame];
}



@end
